package algorithms.sorting


import redirectSystemIn
import redirectSystemOut
import org.junit.jupiter.api.Test
import java.util.*

class InsertionSortTests {
    @Test
    fun insertionSort1Test() {
        redirectSystemIn(this.javaClass, 1) {
            val scan = Scanner(System.`in`)
            redirectSystemOut {
                while (scan.hasNextLine()) {
                    val n = scan.nextLine().trim().toInt()

                    val arr = scan.nextLine().split(" ").map { it.trim().toInt() }.toTypedArray()

                    insertionSort1(n, arr)

                    while (scan.hasNextLine()) {
                        it.add(scan.nextLine())
                    }
                }
            }
        }
    }

    @Test
    fun insertionSort2Test() {
        redirectSystemIn(this.javaClass, 2) {
            val scan = Scanner(System.`in`)
            redirectSystemOut {
                while (scan.hasNextLine()) {
                    val n = scan.nextLine().trim().toInt()

                    val arr = scan.nextLine().split(" ").map { it.trim().toInt() }.toTypedArray()

                    insertionSort2(n, arr)

                    for (i in 1 until n) {
                        it.add(scan.nextLine())
                    }
                }
            }
        }
    }
}